<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch">
      <!--根据比对等级选择-->
      <el-form-item prop="adeMatchLevel">
        <el-select v-model="queryParams.adeMatchLevel" placeholder="Select Ade Match Level" clearable>
          <el-option v-for="dict in dict.type.ade_match_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--根据算法选择-->
      <el-form-item prop="algorithm">
        <el-select v-model="queryParams.algorithm" placeholder="Select algorithm" clearable>
          <el-option v-for="dict in dict.type.ade_llm_algorithm" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--根据LLM 检索-->
      <el-form-item prop="llm">
        <el-select v-model="queryParams.llm" placeholder="Select LLM" clearable>
          <el-option v-for="dict in dict.type.llm_model" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--根据Prompt Type 检索-->
      <el-form-item prop="promptType">
        <el-select v-model="queryParams.promptType" placeholder="Select PromptType" clearable>
          <el-option v-for="dict in dict.type.prompt_type" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>
         <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ade:labkfoldresult:export']">Export</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="labkfoldresultList">
      <!--
      <el-table-column label="Lab ID" width="60" align="center" prop="labId" />
      -->
      <el-table-column label="Algorithm" min-width="110" align="left" prop="algorithm" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ade_llm_algorithm" :value="scope.row.algorithm" />
        </template>
      </el-table-column>

      <el-table-column label="Level" width="80" align="center" prop="adeMatchLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ade_match_level" :value="scope.row.adeMatchLevel" />
        </template>
      </el-table-column>
      <el-table-column label="LLM" min-width="100" align="left" prop="llm" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.llm_model" :value="scope.row.llm" />
        </template>
      </el-table-column>

      <el-table-column label="Prompt" min-width="70" align="left" prop="promptType" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.prompt_type" :value="scope.row.promptType" />
        </template>
      </el-table-column>
      <el-table-column label="Folds" width="80" align="center" prop="folds" />
      <!--precision-->
      <el-table-column label="Precision" width="120" align="center" prop="precisionMean">
        <template slot-scope="scope">
          <div
            v-html="formatToFourDecimals(scope.row.precisionMean) + ' ± ' + formatToFourDecimals(scope.row.precisionSd)" />
        </template>
      </el-table-column>
      <!--recall-->
      <el-table-column label="Recall" width="120" align="center" prop="recallMean">
        <template slot-scope="scope">
          <div v-html="formatToFourDecimals(scope.row.recallMean) + ' ± ' + formatToFourDecimals(scope.row.recallSd)" />
        </template>
      </el-table-column>
      <!--f1-->
      <el-table-column label="F1-Score" width="120" align="center" prop="f1Mean">
        <template slot-scope="scope">
          <div v-html="formatToFourDecimals(scope.row.f1Mean) + ' ± ' + formatToFourDecimals(scope.row.f1Sd)" />
        </template>
      </el-table-column>

      <!--fpr False Postive Rate-->
      <el-table-column label="FPR" width="120" align="center" prop="fprMean">
        <template slot-scope="scope">
          <div v-html="formatToFourDecimals(scope.row.fprMean) + ' ± ' + formatToFourDecimals(scope.row.fprSd)" />
        </template>
      </el-table-column>

      <!--fnr False Negative Rate-->
      <el-table-column label="FNR" width="120" align="center" prop="fnrMean">
        <template slot-scope="scope">
          <div v-html="formatToFourDecimals(scope.row.fnrMean) + ' ± ' + formatToFourDecimals(scope.row.fnrSd)" />
        </template>
      </el-table-column>

      <!--Specificity-->
      <el-table-column label="Specificity" width="120" align="center" prop="specificityMean">
        <template slot-scope="scope">
          <div
            v-html="formatToFourDecimals(scope.row.specificityMean) + ' ± ' + formatToFourDecimals(scope.row.specificitySd)" />
        </template>
      </el-table-column>

      <el-table-column label="Create Time" min-width="150" align="center" prop="createTime" show-overflow-tooltip />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { listLabkfoldresult} from "@/api/ade/labkfoldresult";

export default {
  name: "Labkfoldresult",
  dicts: ['ade_match_level', 'llm_model', 'prompt_type', 'ade_llm_algorithm'],
   props: {
    id: {                 //传入的ID     LAB Analysis ID （一次分析任务的ID）
      type: Number,
      required: true
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // AdeLabKfoldResult表格数据
      labkfoldresultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        algorithm: null,
        labId: null,
        adeMatchLevel: null,
        precisionMean: null,
        recallMean: null,
        f1Mean: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.queryParams.labId = this.id; // 设置labId为传入的ID
    this.getList();
  },
  methods: {
    /** 查询AdeLabKfoldResult列表 */
    getList() {
      this.loading = true;
      this.queryParams.labId = this.id; // 设置labId为传入的ID
      listLabkfoldresult(this.queryParams).then(response => {
        this.labkfoldresultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ade/labkfoldresult/export', {
        ...this.queryParams
      }, `labkfoldresult_${new Date().getTime()}.xlsx`)
    },
    formatToFourDecimals(value) {
      if (!isNaN(value)) {
        const formattedValue = Number(value).toFixed(4);
        if (value >= 0.9) {
          return `<span style="color: green;font-weight:800">${formattedValue}</span>`;
        } else if (value >= 0.8) {
          return `<span style="color: orange;font-weight:800">${formattedValue}</span>`;
        }
        return formattedValue;
      }
      return value; // 如果不是数字，直接返回原值
    }
  }
};
</script>
